package com.lening.provider.controller.OwnersRepair;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lening.common.base.BaseController;
import com.lening.common.excel.ExcelUtils;
import com.lening.provider.dto.OwnersRepair.OwnerRepairMainTableDTO;
import com.lening.provider.po.OwnersRepair.OwnerRepairMainTablePO;
import com.lening.provider.service.OwnersRepair.OwnerRepairMainTableService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.reactive.function.client.WebClient;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 刘政华
 * @datetime 2024/6/5 11:53
 * @description 类对象
 */
@Slf4j
@RestController
@RequestMapping("ownerRepairMainTables")
public class OwnerRepairMainTableController extends BaseController<OwnerRepairMainTablePO, OwnerRepairMainTableDTO, OwnerRepairMainTableService> {

    @Autowired(required = false)
    private WebClient webClient;

    @Autowired
    private OwnerRepairMainTableService ownerRepairMainTableService;

    @Override
    public Page<?> page(OwnerRepairMainTableDTO ownerRepairMainTableDTO) {
        return ownerRepairMainTableService.ownerRepairList(ownerRepairMainTableDTO);
    }

    @GetMapping("/export/{id}")
    public void export(@PathVariable Long id, HttpServletResponse response) {
        // 假设 ownerRepairMainTableService 有一个根据 id 获取数据的方法
        OwnerRepairMainTablePO ownerRepairMainTablePO = ownerRepairMainTableService.getById(id);

        // 如果只有一个对象要导出，你可能想将其放入一个列表中
        List<OwnerRepairMainTablePO> list = new ArrayList<>();
        if (ownerRepairMainTablePO != null) {
            list.add(ownerRepairMainTablePO);
        }

        // 现在，你可能需要修改 ExcelUtils.export 方法来处理只有一个对象的情况
        // 或者，如果它已经能够处理空列表或单个对象，那么可以直接调用它
        ExcelUtils.export(response, "用户报修表", list, OwnerRepairMainTablePO.class);
    }

    @GetMapping("/count")//待处理报修
    public long getCount() {
        return ownerRepairMainTableService.count();
    }
}
